// pages/service_detail/index.js
const appInstance = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    image: 'https://ts1.cn.mm.bing.net/th/id/R-C.a217646500d039d0a039e0a555fa958e?rik=AQVEVmbiBPcN6g&riu=http%3a%2f%2fwww.qifeiye.com%2fqfy-content%2fuploads%2f2017%2f12%2fda7056bc7be73c97caa79618367dc366.gif%3fattachment_id%3d52381&ehk=S28gMPGLVUZaiwtzsYiNAXD%2b7Y226fOrYRTesFkCd3I%3d&risl=&pid=ImgRaw&r=0',
    pre_paid_page_image_list:[],
    search_data:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */


  paid_order(){
    let search_data = this.data.search_data
    let data = search_data[0]
    console.log(data)
    wx.requestPayment({
      timeStamp: data.tmp_time.toString(),
      nonceStr: data.uuid_str,
      package: `prepay_id=${data.prepay_id}`,
      signType: 'RSA',
      paySign: data.signature,
      success (res) {
        console.log(res)
        wx.showToast({
          title: '支付成功',
          icon: 'check',
          duration: 2000
        })
        wx.switchTab({
          url: '/pages/order_list/index'
        })
       },
      fail (err){
        console.log(err)
        wx.showToast({
          title: '支付出错,请联系客服处理',
          icon: 'none',
          duration: 2000
        })
       },    
    })
  },
  onLoad(options) {
    console.log(options)
   let search_records_details_id = options.search_records_details_id
   let service_config_id = options.service_config_id
   let that = this
   let url = appInstance.globalData.request_url + 'search_details'
   let data = {
    search_records_details_id: search_records_details_id,
    service_config_id: service_config_id,
   }
   wx.login({
    success: (res) => {
      wx.request({
        url:url,
        data:Object.assign({wx_code:res.code},data),
         header: {
           'content-type': 'application/json' // 默认值
           // 'content-type': 'null' 
         },
         method:'GET',
         success (res) {
           console.log('成功')
           console.log(res.data)
           if (res.data){
            that.analysis_reps_data(res.data)
           }else{
            let msg = res.data.msg
            console.log(msg)
            // 修改成一报错就隐藏
            wx.showToast({
              title: '支付信息有误,请联系客服',
              duration: 2000
            })
           }
           
         },
         fali (err) {
           console.log(err)
         }
       })
    },
  })

  },
  analysis_reps_data(resp_data){
    console.log(resp_data)
    let search_data = resp_data.resp_data
    let pre_paid_page_image_list = resp_data.pre_paid_page_image_list
    let that = this
    if (resp_data.status == 200){
      // 搜索记录跳转
      that.setData({search_data:search_data,pre_paid_page_image_list:pre_paid_page_image_list})
    }else{
      // 提示用户无搜索记录
      console.log("无详情记录")
      that.setData({search_data:[],display_image:true})
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})